import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style

const whiteList = ['/login', '/404'] // no redirect whitelist

router.beforeEach(async(to, from, next) => {
  if (store.getters.token) {
    store.dispatch('user/getuserInfo' )
    return next()
  }
  if (whiteList.includes(to.path)) {
    return next()
  }
   
  next('/login')
})

router.afterEach(() => {
  // finish progress bar
  NProgress.done()
})
